import { CreateOrderParamType, SHCancelParmaType, SHChangeNumType, SHListQueryType, ShoppingCar_AddType } from "@Tea/model"
import { AppTokenObj } from "../dao/AppToken"
import { ShoppingCarRepository } from "../repo/ShoppingCarRepository"

export class ShoppingCarCtx {
  private static inst: ShoppingCarCtx
  private shoppingCarRepo: ShoppingCarRepository = ShoppingCarRepository.getInstance()

  public static getInstance() {
    if (!ShoppingCarCtx.inst) {
      ShoppingCarCtx.inst = new ShoppingCarCtx()
    }

    return ShoppingCarCtx.inst
  }

  addCommodity(teaId: ShoppingCar_AddType["teaId"], customer: AppTokenObj['userId']) {
    return this.shoppingCarRepo.addCommodity(teaId, customer)
  }

  async shoppingCarList(query: SHListQueryType, customer: AppTokenObj['userId']) { 
    return (await this.shoppingCarRepo.shoppingCarList(query, customer))[0]
  }
  async shoppingCarListByIds(query: CreateOrderParamType["shoppingIds"], customer: AppTokenObj['userId']) { 
    return (await this.shoppingCarRepo.shoppingCarListByIds(query, customer))[0]
  }

  changeNumber(params: SHChangeNumType, customer: AppTokenObj['userId']) {
    return this.shoppingCarRepo.changeNumber(params, customer)
  }

  cancelCommodity(params: SHCancelParmaType, customer: AppTokenObj['userId']) {
    return this.shoppingCarRepo.cancelCommodity(params, customer)
  }
}